package com.shangcheng.item.controller;

import com.shangcheng.item.service.PageService;
import entity.Result;
import entity.StatusCode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@Controller
@RequestMapping("/page")
public class PageController {

    @Autowired
    private PageService pageService;

    /**
     * 生成静态页面
     *
     * @param id
     * @return
     */
    @RequestMapping("/createHtml/{id}")
    public Result createHtml(@PathVariable(name = "id") Long id) {
        pageService.createPageHtml(id);
        return new Result(true, StatusCode.OK, "创建网页成功");
    }


    @GetMapping("/findBy")
    public String pageSku(@RequestParam  Long id,
                          @RequestParam String username, ModelMap model) {
        Map dataMap = pageService.selectBySpuId(id);
        model.addAttribute("username", username);
        model.addAttribute("data", dataMap);
        return "item";
    }
}